package com.spring.myspace.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.fasterxml.jackson.databind.util.JSONPObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mangofactory.swagger.annotations.ApiIgnore;
import com.spring.myspace.web.service.MySpaceService;
import com.spring.security.core.util.ApplicationUtils;

@Controller
@RequestMapping(value = "/mySpace")
@ApiIgnore
public class MySpaceController {

	@Resource
	private MySpaceService mySpaceService;

	/**
	 * 生成日志
	 * @param token
	 * @param c_family_id
	 * @param c_family_member_id
	 * @param title
	 * @param content
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/createJournal")
	@ResponseBody
	//1安卓 2ios
	public Object createJournal(String mapAppType,String osType,String token, String c_family_id, String c_family_member_id, 
			String title, String content,String ispublic,String callback,String latitude,String longitude,String location) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.createJournal(mapAppType,osType,token, c_family_id, c_family_member_id, title, content,
					ispublic,latitude,longitude,location);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	/**
	 * 日志图片添加
	 * @param token
	 * @param my_space_journal_id
	 * @param file
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/addJournalPhoto")
	@ResponseBody
	public Object addJournalPhoto(String token, String my_space_journal_id,
			String c_family_member_id,String file,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.addJournalPhoto(token, my_space_journal_id,c_family_member_id, file);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	/**
	 * 日志视频添加
	 * @param token
	 * @param my_space_journal_id
	 * @param c_family_member_id
	 * @param file_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/addJournalVideo")
	@ResponseBody
	public Object addJournalVideo(String token, String my_space_journal_id,String c_family_member_id,
			String file_id,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.addJournalVideo(token, c_family_member_id, my_space_journal_id, file_id);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	
	
	/**
	 * 日志视频添加封面/修改封面
	 * @param token
	 * @param my_space_video_id
	 * @param file_id
	 * @param c_family_member_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/addJournalVideoCover")
	@ResponseBody
	public Object addJournalVideoCover(String token, String my_space_video_id, String file_id,
			String c_family_member_id,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.addJournalVideoCover(token, my_space_video_id, file_id, c_family_member_id);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	
	/**
	 * 查询日志		
	 * @param token
	 * @param c_family_member_id
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getJournalList")
	@ResponseBody
	public Object  getJournalList(String token,
			String c_family_member_id, String page_size, String page_index,
			String skip, String rows,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.getJournalList(token, c_family_member_id, page_size, page_index, skip, rows);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}		
			
	
	/**
	 * 删除日志
	 * @param token
	 * @param my_space_journal_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/deleteJournal")
	@ResponseBody
	public Object  deleteJournal(String token,String my_space_journal_id,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.deleteJournal(token, my_space_journal_id);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	/**
	 * 删除日志中的图片
	 * @param token
	 * @param photo
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/deleteJournalPhoto")
	@ResponseBody
	public Object  deleteJournalPhoto(String token,String photo,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.deleteJournalPhoto(token, photo);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	/**
	 * 删除日志中的视频
	 * @param token
	 * @param video_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/deleteJournalVideo")
	@ResponseBody
	public Object  deleteJournalVideo(String token,String video_id,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.deleteJournalVideo(token, video_id);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	/**
	 * 删除日志中的视频
	 * @param token
	 * @param video_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/updateJournal")
	@ResponseBody
	public Object  updateJournal(String token,
			String my_space_journal_id, String title, String content,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.updateJournal(token, my_space_journal_id, title, content);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	


/**
 * 创建相册			
 * @param token
 * @param name
 * @param desc
 * @param c_family_id
 * @param c_family_member_id
 * @param isfamily
 * @param callback
 * @return
 */

	@RequestMapping(value = "/createAlbum")
	@ResponseBody
	public Object  createAlbum(String token,String name, String desc, 
			String c_family_id, String c_family_member_id, String isfamily,String ispublic,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
		//	m = mySpaceService.createAlbum(token, name, desc, c_family_id, c_family_member_id, isfamily);
			m = mySpaceService.createAlbum(token, name, desc, c_family_id, c_family_member_id, isfamily,ispublic);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}
	
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	






	/**
	 * 添加图片
	 * @param token
	 * @param my_space_album_id
	 * @param c_family_member_id
	 * @param photo
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/addAlbumPhoto")
	@ResponseBody
	public Object addAlbumPhoto(String token, String my_space_album_id,
			String c_family_member_id, String photo, String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.addAlbumPhoto(token, my_space_album_id,
					c_family_member_id, photo);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	/*
	 * 更新相册图片
	 */
	@RequestMapping(value = "/updateAlbumPhoto")
	@ResponseBody
	public Object updateAlbumPhoto(String token, String photo_id, 
			String name, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.updateAlbumPhoto(token, photo_id, name);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	/**
	 * 设置相册封面
	 * @param token
	 * @param photo_id
	 * @param name
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/setAlbumCover")
	@ResponseBody
	public Object setAlbumCover(String token, String my_space_album_id,
			String file_id, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.setAlbumCover(token, my_space_album_id, file_id);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	
	/**
	 * 得到相册列表
	 * @param token
	 * @param isfamily
	 * @param c_family_member_id
	 * @param c_family_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getAlbumList")
	@ResponseBody
	public Object getAlbumList(String token, String isfamily,
			String c_family_member_id, String c_family_id,String my_space_album_id, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.getAlbumList(token, isfamily, c_family_member_id, c_family_id,my_space_album_id);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	
	/**
	 * 得到图片列表
	 * @param token
	 * @param my_space_album_id
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getAlbumPhotoList")
	@ResponseBody
	public Object getAlbumPhotoList(String token, String my_space_album_id, 
			String page_size, String page_index, String skip, String rows, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.getAlbumPhotoList(token, my_space_album_id, page_size, page_index, skip, rows);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	
	

	/**
	 * 删除相册图片
	 * @param token
	 * @param photo
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/deleteAlbumPhoto")
	@ResponseBody
	public Object deleteAlbumPhoto(String token, String photo, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.deleteAlbumPhoto(token, photo);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	
	
	
	

	
	
			@RequestMapping(value = "/deleteAlbum")
			@ResponseBody
			public Object deleteAlbum(String token, String my_space_album_id, String callback) {

				Map<String, Object> m = new HashMap<String, Object>();
				try {

					m = mySpaceService.deleteAlbum(token, my_space_album_id);

				} catch (Exception e) {
					m.put(ApplicationUtils.STATUS, "0");
					m.put(ApplicationUtils.MSG, "系统异常");
					e.printStackTrace();

				}

				if (ApplicationUtils.isNotNull(callback)) {
					return new JSONPObject(callback, m);
				} else {
					return m;
				}
			}	
			
			
			
	
	/**
	 * 修改相册
	 * @param token
	 * @param name
	 * @param desc
	 * @param my_space_album_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/updateAlbum")
	@ResponseBody
	public Object updateAlbum(String token, String name, String desc,String my_space_album_id, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.updateAlbum(token, name, desc, my_space_album_id);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	
    /**
     * 添加视频
     * @param token
     * @param file_id
     * @param c_family_member_id
     * @param c_family_id
     * @param isfamily
     * @param title
     * @param content
     * @param callback
     * @return
     */
	@RequestMapping(value = "/addVideo")
	@ResponseBody
	public Object addVideo(String token, String file_id, String c_family_member_id, 
			String c_family_id, String isfamily, String title, String content,String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.addVideo(token, file_id, c_family_member_id, c_family_id, isfamily, title, content);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	
	
	
	/**
	 * 添加视频封面
	 * @param token
	 * @param video_id
	 * @param file_id
	 * @param c_family_member_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/addVideoCover")
	@ResponseBody
	public Object addVideoCover(String token, String video_id, String file_id, 
			String c_family_member_id,String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.addVideoCover(token, video_id, file_id, c_family_member_id);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	/**
	 * 更新视频
	 * @param token
	 * @param title
	 * @param content
	 * @param video_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/updateVideo")
	@ResponseBody
	public Object updateVideo(String token, String title, String content, 
			String video_id,String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.updateVideo(token, title, content, video_id);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	/**
	 * 得到视频列表
	 * @param token
	 * @param isfamily
	 * @param c_family_member_id
	 * @param c_family_id
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getVideoList")
	@ResponseBody
	public Object getVideoList(String token, String isfamily, 
			String c_family_member_id, String c_family_id, String page_size, 
			String page_index, String skip, String rows,String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = mySpaceService.getVideoList(token, isfamily, c_family_member_id, c_family_id, page_size, page_index, skip, rows);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	
	
	/**
	 * 删除视频
	 * @param token
	 * @param video_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/deleteVideo")
	@ResponseBody
	public Object deleteVideo(String token,
			String video_id,String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = mySpaceService.deleteVideo(token, video_id);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
}
